#include <bits/stdc++.h>
using namespace std;
int main()
{
	int t;
	cin >> t;
	while(t--)
	{
		string s;
		cin >> s;
		deque <char> q;
		for(int i=0;i<s.size();i++)
		{
			q.push_back(s[i]);
			int n=q.size();
			if(n>=2&&q[n-1]==')'&&q[n-2]=='(')
			{
				q.pop_back();
				q.pop_back();
			}
		}
		if(q.empty())
		{
			cout << "YES" << endl;
		}
		else
		{
			cout << "NO" << endl;
		}
	}
}
